\subsection{Height and dimension}
Recall that for a prime ideal \( \mathfrak p \) in \( R \), its \emph{height} is the largest \( n \) such that there exists a chain of inclusions of prime ideals
\[ \mathfrak p_0 \subsetneq \mathfrak p_1 \subsetneq \dots \subsetneq \mathfrak p_n = \mathfrak p \]
For example, if \( R \) is an integral domain, a prime ideal is of height 1 if and only if no nonzero prime ideal is strictly contained within it.
\begin{example}
    \begin{enumerate}
        \item In any integral domain, \( (0) \) has height 0.
        \item In \( \mathbb C[x, y] \), the ideal \( (x) \) has height 1, and the ideal \( (x, y) \) has height 2.
    \end{enumerate}
\end{example}
It can be shown that in a unique factorisation domain, every prime ideal of height 1 is principal.

We will globalise the notion of height 1 prime ideals, giving \emph{Weil divisors}, and also the notion of principal ideals, giving \emph{Cartier divisors}.
In the case of Weil divisors, we will assume that the ambient scheme \( X \) is Noetherian, integral, separated, and \emph{regular in codimension 1}.

If \( X \) is integral and \( U = \Spec A \) is an open affine, then the ideal \( (0) \subseteq A \) is called the \emph{generic point} of \( X \).
Each open affine is dense as they are irreducible, so they have a nontrivial intersection, including their generic points.
The generic points given by each \( U \) therefore coincide in \( X \).
This point is often denoted by \( \eta \) or \( \eta_X \).
\begin{definition}
    Let \( X \) be a scheme.
    \begin{enumerate}
        \item The \emph{dimension} of \( X \) is the length \( n \) of the longest chain of nonempty closed irreducible subsets
        \[ Z_0 \subsetneq Z_1 \subsetneq \dots \subsetneq Z_n \]
        \item Let \( Z \subseteq X \) be closed and irreducible.
        The \emph{codimension} of \( X \) is the length \( n \) of the longest chain
        \[ Z = Z_0 \subsetneq Z_1 \subsetneq \dots \subsetneq Z_n \]
        \item If \( X \) is a \emph{Noetherian topological space}, so every decreasing sequence of closed subsets stabilises, then every closed \( Z \subseteq X \) has a decomposition into finitely many irreducible closed subsets.
        \item Suppose \( X \) is Noetherian, integral, and separated.
        We say that \( X \) is \emph{regular in codimension 1} if for every subspace \( Y \subseteq X \) that is closed, irreducible, and of codimension 1, if \( \eta_Y \) denotes the generic point of \( Y \), then \( \mathcal O_{X, \eta_Y} \) is a discrete valuation ring, or equivalently a local principal ideal domain.
    \end{enumerate}
\end{definition}

\subsection{Weil divisors}
\begin{definition}
    Let \( X \) be Noetherian, integral, separated, and regular in codimension 1.
    A \emph{prime divisor} on \( X \) is an integral closed subscheme of codimension 1.
    A \emph{Weil divisor} on \( X \) is an element of the free abelian group \( \operatorname{Div}(X) \) generated by the prime divisors.
\end{definition}
We will write \( D \in \operatorname{Div}(X) \) as \( \sum_i n_{Y_i} [Y_i] \) where the \( Y_i \) are prime divisors.
\begin{definition}
    A Weil divisor \( \sum_i n_{Y_i} [Y_i] \) is \emph{effective} if all \( n_{Y_i} \) are nonnegative.
\end{definition}
If \( X \) is integral, for \( \Spec A = U \subseteq X \), the local ring \( \mathcal O_{X, \eta} \) is a field, as it is in particular the fraction field of \( A \).
Indeed, because \( \eta \) is contained in every open affine, \( \mathcal O_{X, \eta} \) permits arbitrary denominators.

Let \( f \in \mathcal O_{X, \eta_X} = k(X) \) be nonzero.
Since for every prime divisor \( Y \subseteq X \), the ring \( \mathcal O_{X, \eta_Y} \) is a discrete valuation ring, we can calculate the valuation \( \nu_Y(f) \) of \( f \) in this ring.
We thus define the divisor
\[ \operatorname{div}(f) = \sum_{Y \subseteq X \text{ prime}} \nu_Y(f) [Y] \]
We claim that this is a Weil divisor; that is, the sum is finite.
\begin{proposition}
    The sum
    \[ \sum_{Y \subseteq X \text{ prime}} \nu_Y(f) [Y] \]
    is finite.
\end{proposition}
\begin{proof}
    Let \( f \in k(X)^\times \), and choose \( A \) such that \( U = \Spec A \) is an affine open, so \( FF(A) = k(X) \).
    We can also require that \( f \in A \) by localising at the denominator, so \( f \) is \emph{regular} on \( U \).
    Then \( X \setminus U \) is closed and of codimension at least 1, so only finitely many prime Weil divisors \( Y \) of \( X \) are contained in \( X \setminus U \).
    On \( U \), as \( f \) is regular, \( \nu_Y(f) \geq 0 \) for all \( Y \).
    But \( \nu_Y(f) > 0 \) if and only if \( Y \) is contained in \( \mathbb V(f) \subseteq U \), and by the same argument, there are only finitely many such \( Y \).
\end{proof}
\begin{definition}
    A Weil divisor of the form \( \operatorname{div}(f) \) is called \emph{principal}.
    In \( \operatorname{Div}(X) \), the set of principal divisors form a subgroup \( \operatorname{Prin}(X) \), and we define the \emph{Weil divisor class group} of \( X \) to be
    \[ \operatorname{Cl}(X) = \faktor{\operatorname{Div}(X)}{\operatorname{Prin}(X)} \]
\end{definition}
\begin{remark}
    \begin{enumerate}
        \item Let \( A \) be a Noetherian domain.
        Then \( A \) is a unique factorisation domain if and only if \( A \) is integrally closed and \( \operatorname{Cl}(\Spec A) \) is trivial.
        This is related to the fact that in unique factorisation domains, all primes of height 1 are principal.
        In particular, there exist rings with nontrivial class groups of their spectra.
        \item \( \operatorname{Cl}(\mathbb A^n_k) = 0 \).
        \item \( \operatorname{Cl}(\mathbb P^n_k) \cong \mathbb Z \); we will prove this shortly.
        % TODO: break here, organise into props/proofs
        \item Let \( Z \subseteq X \) is closed, and let \( U = X \setminus Z \).
        Then there is a surjective map \( \operatorname{Cl}(X) \twoheadrightarrow \operatorname{Cl}(U) \), defined by \( [Y] \mapsto [Y \cap U] \), but instead mapping \( [Y] \) to zero if \( Y \cap U = \varnothing \).
        This is well-defined, as \( k(X) \) and \( k(U) \) are naturally isomorphic, so principal divisors are mapped to principal divisors.
        For surjectivity, note that given a prime Weil divisor \( D \subseteq U \), its closure \( \overline D \) in \( X \) is a prime Weil divisor that restricts to \( D \) under the map.
        \item If \( Z \) has codimension at least 2, then \( \operatorname{Cl}(X) \twoheadrightarrow \operatorname{Cl}(U) \) is an isomorphism.
        This is because \( Z \) does not enter the definition of \( \operatorname{Cl}(X) \).
        \item If \( Z \subseteq X \) is integral, closed, and of codimension 1, there is an exact sequence
        % https://q.uiver.app/#q=WzAsNCxbMCwwLCJcXG1hdGhiYiBaIl0sWzEsMCwiXFxvcGVyYXRvcm5hbWV7Q2x9KFgpIl0sWzIsMCwiXFxvcGVyYXRvcm5hbWV7Q2x9KFUpIl0sWzMsMCwiMCJdLFswLDEsIjEgXFxtYXBzdG8gW1pdIl0sWzEsMl0sWzIsM11d
        \[\begin{tikzcd}
            {\mathbb Z} & {\operatorname{Cl}(X)} & {\operatorname{Cl}(U)} & 0
            \arrow["{1 \mapsto [Z]}", from=1-1, to=1-2]
            \arrow[from=1-2, to=1-3]
            \arrow[from=1-3, to=1-4]
        \end{tikzcd}\]
        called the \emph{excision} exact sequence.
        Indeed, the kernel of \( \operatorname{Cl}(X) \to \operatorname{Cl}(U) \) are exactly the divisors in \( X \) contained in \( Z \).
    \end{enumerate}
\end{remark}
\begin{proposition}
    Let \( k \) be a field.
    Then, \( \operatorname{Cl}(\mathbb P^n_k) \cong \mathbb Z \).
\end{proposition}
\begin{proof}
    Let \( D \subseteq \mathbb P^n \) be integral, closed, and of codimension 1.
    Then \( D = \mathbb V(f) \) where \( f \) is homogeneous of some degree \( d \); we will define \( \deg(D) = d \).
    We extend linearly to obtain a homomorphism \( \deg : \operatorname{Div}(\mathbb P^n_k) \to \mathbb Z \).
    We claim that this gives an isomorphism \( \operatorname{Cl}(\mathbb P^n_k) \to \mathbb Z \).
    First, this is well defined on classes, since if \( f = \frac{g}{h} \) is a rational function, then \( g \) and \( h \) are homogeneous polynomials of the same degree, so \( \deg(\operatorname{div}(f)) = 0 \).
    This is surjective, by taking \( H = \mathbb V(x_0) \) for \( x_0 \) homogeneous linear.
    For injectivity, suppose \( D = \sum n_{Y_i} [Y_i] \) with \( \sum n_{Y_i} \deg(Y_i) = 0 \).
    Write \( Y_i = \mathbb V(g_i) \), and let \( f = \prod g_i^{n_{Y_i}} \).
    Now \( f \) is a homogeneous rational function of degree zero.
\end{proof}

\subsection{Cartier divisors}
Let \( X \) be a scheme.
Consider the presheaf on \( X \) given by mapping \( U = \Spec A \) to \( S^{-1}A \) where \( S \) is the set of all elements that are not zero divisors.
Sheafification yields the sheaf of rings \( \mathcal K_X \).
Define \( \mathcal K_X^\star \subseteq \mathcal K_X \) to be the subsheaf of invertible elements; this is a sheaf of abelian groups under multiplication.
If \( X \) is integral, then \( \mathcal K_X \) is the constant sheaf, where the constant field is \( \mathcal O_{X,\eta_X} = FF(A) \) for any affine open \( \Spec A \).

Similarly, let \( \mathcal O_X^\star \subseteq \mathcal O_X \) be the subsheaf of invertible elements.
Thus, every section of \( \faktor{\mathcal K_X^\star}{\mathcal O_X^\star} \) can be prescribed by \( \qty{(U_i, f_i)} \) where \( U_i \) is a cover of \( X \), \( f_i \) is a section of \( \mathcal K_X^\star(U_i) \), and that on \( U_i \cap U_j \), the ratio \( \faktor{f_i}{f_j} \) lies in \( \mathcal O_X^\star(U_i \cap U_j) \).
\begin{definition}
    A \emph{Cartier divisor} is a global section of the sheaf \( \faktor{\mathcal K_X^\star}{\mathcal O_X^\star} \).
\end{definition}
We have a surjective sheaf homomorphism \( \mathcal K_X^\star \to \faktor{\mathcal K^X_\star}{\mathcal O_X^\star} \), but a global section of \( \faktor{\mathcal K^X_\star}{\mathcal O_X^\star} \) is not necessarily the image of a global section of \( \mathcal K_X^\star \).
\begin{definition}
    The image of \( \Gamma(X, \mathcal K_X^\star) \) in \( \Gamma\qty(X, \faktor{\mathcal K_X^\star}{\mathcal O_X^\star}) \) is the set of \emph{principal} Cartier divisors.
    The \emph{Cartier class group} is the quotient
    \[ \faktor{\Gamma\qty(X, \faktor{\mathcal K_X^\star}{\mathcal O_X^\star})}{\im \Gamma(X, \mathcal K_X^\star)} \]
\end{definition}
A section \( \mathcal D \in \Gamma\qty(X, \faktor{\mathcal K_X^\star}{\mathcal O_X^\star}) \) can be specified by \( \qty{(U_i, f_i)} \) where the \( \qty{U_i} \) form an open cover and \( f_i \in \mathcal K_X^\star(U_i) \), such that on \( U_i \cap U_j \), the quotient \( \frac{f_i}{f_j} \) lies in \( \mathcal O_X^\star(U_i \cap U_j) \).

Let \( X \) be Noetherian, integral, separated, and regular in codimension 1.
Given a Cartier divisor \( \mathcal D \in \Gamma\qty(X, \faktor{\mathcal K_X^\star}{\mathcal O_X^\star}) \), we obtain a Weil divisor as follows.
If \( Y \subseteq X \) is a prime Weil divisor and its generic point is \( \eta_Y \), we represent \( \mathcal D \) by \( \qty{(U_i, f_i)} \) and set \( n_Y \) to be \( \nu_Y(f_i) \) for some \( U_i \) containing \( \eta_Y \).
Then we obtain the Weil divisor
\[ \sum_{Y \subseteq X} n_Y [Y] \]
This is well-defined: if \( \eta_Y \) is contained in both \( U_i \) and \( U_j \), the valuations of \( f_i \) and \( f_j \) differ by \( \nu_Y\qty(\frac{f_i}{f_j}) \), but \( \frac{f_i}{f_j} \) is a unit, so has valuation zero.
Similarly, one can show that this is independent of the choice of representative of \( \mathcal D \).
\begin{proposition}
    Let \( X \) be Noetherian, integral, separated, and regular in codimension 1.
    Suppose that all local rings \( \mathcal O_{X,x} \) are unique factorisation domains.
    Then the association of a Weil divisor to each Cartier divisor is a bijection, and furthermore, is a bijection of principal divisors.
\end{proposition}
\begin{proof}[Proof sketch]
    If \( R \) is a unique factorisation domain, then all height 1 prime ideals are principal.
    If \( x \in X \), then \( \mathcal O_{X, x} \) is a unique factorisation domain by hypothesis, so given a Weil divisor \( D \), we can restrict it to \( \Spec \mathcal O_{X, x} \to X \).
    But on \( \Spec \mathcal O_{X, x} \), \( D \) is given by \( \mathbb V(f_x) \) as \( \mathcal O_{X, x} \) is a unique factorisation domain.
    \( f_x \) extends to some neighbourhood \( U_x \) containing \( x \), then the \( f_x \) can be glued to form a Cartier divisor.
    This can be checked to be bijective.
\end{proof}
Given a Cartier divisor \( D \) on \( X \) with representative \( \qty{(U_i, f_i)} \), we can define \( L(\mathcal D) \subseteq \mathcal K_X \) to be the sub-\( \mathcal O_X \)-module generated on \( U_i \) by \( f_i^{-1} \).
Note that if \( X = \Spec A \) where \( A \) is integral, and \( \mathcal D = \qty{(X, f)} \) where \( f \in A \), then \( A_f \subseteq FF(A) \) is an \( A \)-module.
\begin{proposition}
    The sheaf \( L(\mathcal D) \) is a line bundle.
\end{proposition}
\begin{proposition}
    On \( U_i \), we have an isomorphism \( \mathcal O_{U_i} \to \eval{L(\mathcal D)}_{U_i} \) given by \( 1 \mapsto f_i^{-1} \).
\end{proposition}
Consider \( X = \mathbb P^n_k \), and let \( D \) be the Weil divisor \( \mathbb V(x_0) \).
Let \( \mathcal D \) be the corresponding Cartier divisor.
One can show that \( \mathcal O_{\mathbb P^n_k}(1) \cong L(\mathcal D) \).
\begin{remark}
    A line bundle \( L \) on \( X \) has an `inverse' under the tensor product; that is, defining \( L^{-1} = \Hom_{\mathcal O_X}(L, \mathcal O_X) \), we obtain \( L \otimes_{\mathcal O_X} L^{-1} = \mathcal O_X \).
    Tensor products of line bundles are also line bundles.
    If all Weil divisors are Cartier, then \( L(\mathcal D + \mathcal E) = L(\mathcal D) \otimes L(\mathcal E) \).
\end{remark}
\begin{definition}
    The \emph{Picard group} of \( X \) is the set of line bundles on \( X \) up to isomorphism, which forms an abelian group under the tensor product.
\end{definition}
Under mild assumptions, for example assuming that \( X \) is integral, the map \( \mathcal D \mapsto L(\mathcal D) \) is surjective, and the kernel is exactly the set of principal Cartier divisors.
